home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / HyperCard Goodies / Serial Toolkit / Source Code / SPortConfiguration.p < prev    next >
Text File  |  1988-11-18  |  4KB  |  142 lines

  1. (*
  2.     SPortConfiguration() -- Returns a string containing the current configuration of the port. The string
  3.         is in the same format as the parameters passed to configureSPort.
  4.  
  5.     To compile and link this file using Macintosh Programmer's Workshop,
  6.  
  7.         pascal -w SPortConfiguration.p
  8.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=7036 -sn Main=SPortConfiguration ∂
  9.             SPortConfiguration.p.o "{MPW}"Libraries:interface.o "{MPW}"PLibraries:PasLib.o
  10.  
  11.     © Copyright 1987,88 by Apple Computer, Inc.
  12.  
  13.     Initial coding 9/87 by Harry R. Chesley.
  14. *)
  15.  
  16. {$R-}
  17.  
  18. {$S SPortConfiguration }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. type
  31.  
  32. Str31 = String[31];
  33.  
  34. procedure SPortConfiguration(paramPtr: XCmdPtr); forward;
  35.  
  36. procedure EntryPoint(paramPtr: XCmdPtr);
  37.  
  38.     begin
  39.         SPortConfiguration(paramPtr);
  40.     end;
  41.  
  42. procedure SPortConfiguration(paramPtr: XCmdPtr);
  43.  
  44.     var theConfiguration: str255;
  45.         i: integer;
  46.  
  47.     {$I XCmdGlue.inc}
  48.  
  49.     procedure Fail(errMsg: Str255); { set theResult and quit }
  50.         begin
  51.             paramPtr^.returnValue := PasToZero(errMsg);
  52.             exit(SPortConfiguration);
  53.         end;
  54.  
  55.     {$I SPortUtil.inc}
  56.  
  57.     procedure concatStr(str: str255);
  58.  
  59.         begin
  60.             theConfiguration := Concat(theConfiguration,str);
  61.         end;
  62.  
  63.     procedure concatOnOff(name: str255; onOff: boolean);
  64.  
  65.         begin
  66.             concatStr(',');
  67.             concatStr(name);
  68.             if onOff then concatStr('On')
  69.             else concatStr('Off');
  70.         end;
  71.  
  72.     begin
  73.         if paramPtr^.paramCount <> 0 then Fail('parameter count is not 0');
  74.  
  75.         SetUpSPortGlobals;
  76.  
  77.         { Start with the port: }
  78.         if Globals^^.selectedPort = sPortA then theConfiguration := 'modemPort'
  79.         else theConfiguration := 'printerPort';
  80.  
  81.         with ThisSPort do
  82.             begin
  83.                 { Add in the baud rate: }
  84.                 case BitAnd(byteConfig,$3FF) of
  85.                     baud300: concatStr(',baud300');
  86.                     baud600: concatStr(',baud600');
  87.                     baud1200: concatStr(',baud1200');
  88.                     baud1800: concatStr(',baud1800');
  89.                     baud2400: concatStr(',baud2400');
  90.                     baud3600: concatStr(',baud3600');
  91.                     baud4800: concatStr(',baud4800');
  92.                     baud7200: concatStr(',baud7200');
  93.                     baud9600: concatStr(',baud9600');
  94.                     baud19200: concatStr(',baud19200');
  95.                     baud57600: concatStr(',baud57600');
  96.                     end;
  97.  
  98.                 { And the stop bits: }
  99.                 { This is what the following code should look like, but the compile doesn't seem to be able to handle it:
  100.                             case integer(BitAnd(byteConfig,$0C000)) of
  101.                                 stop10: concatStr(',stop10');
  102.                                 stop15: concatStr(',stop15');
  103.                                 stop20: concatStr(',stop20');
  104.                                 end;}
  105.                 i := BitAnd(byteConfig,$0C000);
  106.                 if i = stop10 then concatStr(',stop10')
  107.                 else if i = stop15 then concatStr(',stop15')
  108.                 else if i = stop20 then concatStr(',stop20');
  109.  
  110.                 { And the parity: }
  111.                 case integer(BitAnd(byteConfig,$03000)) of
  112.                     noParity: concatStr(',parityOff');
  113.                     oddParity: concatStr(',parityOdd');
  114.                     evenParity: concatStr(',parityEven');
  115.                     end;
  116.  
  117.                 { And the number of data bits: }
  118.                 case integer(BitAnd(byteConfig,$00C00)) of
  119.                     data5: concatStr(',data5');
  120.                     data6: concatStr(',data6');
  121.                     data7: concatStr(',data7');
  122.                     data8: concatStr(',data8');
  123.                     end;
  124.  
  125.                 { And flow control: }
  126.                 concatOnOff('XOnOut',shakes.fXOn <> 0);
  127.                 concatOnOff('CTSOut',shakes.fCTS <> 0);
  128.  
  129.                 { Misc. control parameters: }
  130.                 concatOnOff('linefeed',sendLFs);
  131.                 concatOnOff('echo',doEcho);
  132.                 concatOnOff('edit',doEdit);
  133.                 concatOnOff('strip',stripIncoming);
  134.                 concatOnOff('stripControls',stripControls);
  135.                 concatOnOff('autoWrap',autoWrap);
  136.             end;
  137.  
  138.         { Return the complete configuration. }
  139.         paramPtr^.returnValue := PasToZero(theConfiguration);
  140.     end;
  141. end.
  142.